//
//  LJP_CustomTableViewCell.m
//  God_is_a_Girl
//
//  Created by 李继鹏 on 15/10/2.
//  Copyright (c) 2015年 呸. All rights reserved.
//

#import "LJP_CustomTableViewCell.h"
#import "LJP_DaysModel.h"
#import <UIImageView+WebCache.h>

@implementation LJP_CustomTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.picture = [[UIImageView alloc] init];
        self.Content = [[UILabel alloc] init];
        self.picture.layer.cornerRadius = 5;
        self.picture.layer.masksToBounds = YES;
        self.time = [[UILabel alloc] init];
        self.Content.numberOfLines = 0;
        self.time.font = [UIFont systemFontOfSize:13];
        self.backView = [[BaseView alloc] init];
        self.backView.backgroundColor = [UIColor whiteColor];
        self.backView.layer.cornerRadius = 5;
        self.backView.layer.masksToBounds = YES;
        [self.backView addSubview:self.picture];
        [self.backView addSubview:self.Content];
        [self.backView addSubview:self.time];
        self.time.textColor = [UIColor colorWithWhite:0.500 alpha:1.000];
        [self.contentView addSubview:self.backView];
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat f = self.contentView.frame.size.height;
//    UIImage *temp = [UIImage imageNamed:@"search"];
    if (self.picture.frame.size.width != 1) {
        
        self.picture.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width - 30, f - 29 - [self.Content.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 30, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil].size.height);
    }else{
//        self.picture.frame = CGRectMake(0, 0, 1, 0);
    }
    self.Content.frame = CGRectMake(0, f - 26 - [self.Content.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 30, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil].size.height, [UIScreen mainScreen].bounds.size.width - 30, [self.Content.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 30, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil].size.height);
    [self.Content sizeToFit];
    self.time.frame = CGRectMake(0, f - 23, [UIScreen mainScreen].bounds.size.width - 30, 20);
    self.backView.frame = CGRectMake(15, 0, [UIScreen mainScreen].bounds.size.width - 30, f);
}
- (void)setModel:(LJP_DaysModel *)model
{
    if (model != _model) {
        _model = model;
    }
    if (_model.photo.length != 0) {
        [self.picture sd_setImageWithURL:[NSURL URLWithString:_model.photo] placeholderImage:[UIImage imageNamed:@"search"]];
        self.picture.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width - 30, ([UIScreen mainScreen].bounds.size.width - 30) / self.picture.image.size.width * self.picture.image.size.height);
    }else{
        self.picture.frame = CGRectMake(0, 0, 1, 0);
    }
    self.Content.text = _model.text;
    self.time.text = _model.local_time;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
